package com.xyh.flowershop.controller;

import com.xyh.flowershop.service.FileService;
import com.xyh.flowershop.vo.resp.common.ResultRespVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

@RestController("Test")
@RequestMapping("/test/")
public class TestController {

    private final FileService fileService;

    public TestController(FileService fileService) {
        this.fileService = fileService;
    }

    @GetMapping("demo")
    public ResultRespVo testDemo(){
        return ResultRespVo.info(200, "数据传输成功");
    }


    @PostMapping("demo/list")
    public ResultRespVo testDemoList(){
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(i+1);
        }
        return ResultRespVo.success(200, "数据传输成功",list );
    }

    @GetMapping("demo/{id}")
    public ResultRespVo testDemoList(@PathVariable("id") Integer id){

        return ResultRespVo.success(200, "数据传输成功",id );
    }

    @PostMapping("upload")
    public  ResultRespVo testUpload(@RequestParam MultipartFile file ){
        String baseAvatarUrl = "http://localhost:8000/avatar/";
        String fileUrl = fileService.uploadFile(file, "avatar");
        return ResultRespVo.success(200, "上传成功", baseAvatarUrl+ fileUrl);

    }
}
